package org.example.text;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.List;

/**
 * @Auther:Liu
 * @Testname:StringList
 * @Date:2025/8/11 17:34
 */
@SpringBootTest
@Slf4j
public class StringList {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Test
    public void a(){
        ListOperations<String, String> ops = stringRedisTemplate.opsForList();
        ops.leftPush("A","a1");
        ops.leftPush("A","b1");
        ops.leftPush("A","12","23");
        ops.rightPush("A","b2");
        ops.rightPush("A","b3","b4");
        ops.leftPushAll("A","b5","b6","b7","b8","b9");
        ops.leftPushIfPresent("A","b6");
        ops.rightPushAll("A","b7","b8","b9");
        ops.rightPushIfPresent("A","b8");
    }
    @Test
    public void b(){
        ListOperations<String, String> ops = stringRedisTemplate.opsForList();
        List<String> a = ops.range("A", 0, -1);
        log.info("a:{}",a);
        List<String> b = ops.range("A", 0, 4);
        log.info("b:{}",b);
    }

    @Test
    public void c(){
        ListOperations<String, String> ops = stringRedisTemplate.opsForList();
        String a = ops.index("A", 4);
        log.info("a:{}",a);
        Long l = ops.indexOf("A", "b2");
        log.info("l:{}",l);
        Long l1 = ops.lastIndexOf("A", "b2");
        log.info("l1:{}",l1);
        List<String> a1 = ops.leftPop("A", 2);
        log.info("a1:{}",a1);
        Long a2 = ops.size("A");
        log.info("a2:{}",a2);
        ops.trim("A", 0, - 1);
    }
}
